﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Printing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Cef.Utility.Helper;

namespace CefSharp.MinimalExample.WinForms
{
    public partial class PrintSettingForm : Form
    {

        public PrintSettingForm()
        {
            InitializeComponent();
            InitprinterComboBox();
        }

        private void SetDefaultPrinterBtn_Click(object sender, EventArgs e)
        {
            if (PrinterComboBox.SelectedItem != null) //判断是否有选中值
            {
                if (PrinterHelper.SetDefaultPrinter(PrinterComboBox.SelectedItem.ToString())) //设置默认打印机
                {
                    MessageBox.Show(PrinterComboBox.SelectedItem.ToString() + "设置为默认打印机成功！");
                }
                else
                {
                    MessageBox.Show(PrinterComboBox.SelectedItem.ToString() + "设置为默认打印机失败！");
                }
            }
        }
        //获取本机默认打印机名称
        
        
        private void InitprinterComboBox()
        {
            List<String> list = PrinterHelper.GetLocalPrinters(); //获得系统中的打印机列表
            foreach (String s in list)
            {
                PrinterComboBox.Items.Add(s); //将打印机名称添加到下拉框中
            }

            if (!string.IsNullOrEmpty(PrinterHelper.DefaultPrinter()))
            {
                PrinterComboBox.SelectedItem = PrinterHelper.DefaultPrinter();
            }
        }

    }
}
